﻿CREATE PROCEDURE [acms].[UserCustomProperty_Put]
	@UserId int, 
	@Name varchar(50),
	@Value varchar(2000),
	@ConcurencyId rowversion,
	@IdOut int output,
	@ConcurencyIdOut rowversion output
AS
	if exists (select null from [UserCustomProperty_View] with (nolock) where UserId = @UserId and Name = @Name)
	begin
		update UserCustomProperty
		set
			Value = @Value
		where 
			UserId = @UserId 
			and Name = @Name
			and ConcurencyId = @ConcurencyId
		if @@rowcount = 0
			return -100
	end
	else
	begin
		insert into UserCustomProperty
			(UserId, Name, Value)
		values
			(@UserId, @Name, @Value)
	end
	select @IdOut = Id, @ConcurencyIdOut = ConcurencyId from [UserCustomProperty_View] with (nolock) where UserId = @UserId and Name = @Name
RETURN 0;